/*
 * Copyright (c) 2022. All rights reserved.
 * Please don't try to modify the code, because I don't know what the consequences will be.
 *
 *
 *
 *
 *
 *
 *
 */

package cc.zzone.config;

import cc.zzone.bean.LogRecordInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;

/**
 * 日志信息记录拦截器配置
 *
 * @author jinzhengze
 * @since 2022年8月2日
 */
@Configuration
public class LogConfig implements WebMvcConfigurer {

    @Resource
    private LogRecordInterceptor interceptor;
    private static final String[] INTERCEPT_PATH = new String[]{"/**"};
    private static final String[] PASS_PATH = new String[]{
            "/error",
            "/static/**",
            "/js/**",
            "/css/**",
            "/index.html",
            "/webjars/**",
            "/v2/**",
            "/v3/**",
            "/swagger-ui/**",
            "/swagger-ui.html",
            "/swagger-resources/**",
            "/druid/**"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(interceptor);
        registration.addPathPatterns(Arrays.asList(INTERCEPT_PATH));
        registration.excludePathPatterns(Arrays.asList(PASS_PATH));
    }
}
